<?php
/*
Cogumelo v0.1 - INNOTO
Copyright (C) 2009 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@innoto.es>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/

//
// New passwd reset e-mail alert controller
//
require_once("Classes/Controllers/Mail/MailController.inc");
require_once("Classes/Controllers/Data/SolicitudController.inc");
require_once("Classes/Utils/phpMailer/MailSenderPhpMailer.inc");
require_once("Classes/Model/VO/SolicitudVO.inc");
include("Conf/setup.inc");

class PasswdMailController extends MailController
{

	protected $destinations;
	protected $solicitudcontrol;
	protected $solicitud;
	
	
	//
	// Constructor
	//
	function __construct()
     {
      
     parent::__construct();
   
     $this->solicitudcontrol= new SolicitudController();
     $this->mailcontrol = new MailSenderPhpMailer(solicitudFromEmail,solicitudFromName);

     // Set destinations     
     $this->mailcontrol->resetDestination();
  
          
      //Read Template     
      if($handler=fopen(passwdTemplate, "r"))
	   {
	    $this->contentTemplate = fread($handler,filesize(passwdTemplate)); // Read the email template to be send
		fclose($handler);
	   }
	   else (die("Cannot Open Template file for sending e-mails"));
      
       $this->mailcontrol->setSubject(passwdSubject);	   	   
	   $this->tags=array("<LINKAUTH>");
	         
     }

 public function mailnewsolicitud($id)
 {
 	 	
  if($this->solicitud=$this->solicitudcontrol->Find($id)) //If solicitud exists...
  {
     	     
  	$this->mailcontrol->addDestination($this->solicitud->getEmail());	
  	$replace=array(site_url."/index.php?q=passwdchange&uid=".$this->solicitud->getId()."&auth=".$this->solicitud->getAuth()."&class=".$this->solicitud->getClass());
  	$content_replaced = str_replace($this->tags,$replace,$this->contentTemplate);
    	
  	$this->mailcontrol->setContent($content_replaced);  
  	$this->mailcontrol->sendMail(); // Send e-mail!!!
  	$this->logcontrol->addLogLine("New passwd reset request sent. Solicitud ID=".$this->solicitud->getId(), 3);
  }
  
}

 
}
?>